/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package baza;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
 *
 * @author Cyga
 */
public class DBManager {
    private static DBManager instance;
    private EntityManagerFactory emf;
    private DBManager(){}
    
    
    public synchronized static DBManager getManager(){
    if(instance==null){
        instance=new DBManager();
    }
    return instance;
    }
    public EntityManagerFactory createEntityManagerFactory(){
    if(emf==null){
        System.out.print("jestem");
        emf=Persistence.createEntityManagerFactory("paiPU");
    }
    return emf;
    }
    public EntityManager createEntityManager(){
    return this.createEntityManagerFactory().createEntityManager();
    }
    public void closeEntityManagerFactory(){
    if(emf != null){
        emf.close();
    }
    }
    
    
}
